package com.example.testcentral.designpattern.ObserverPattern

import com.mobile.centaur.utils.LogUtils

/**
 * File Name: CurrentConditionsDisplay
 * Author: zhangzhenzhong
 * Created on: 2024/7/8
 * Description:订阅者-观察者
 */
class CurrentConditionsDisplay :Observer,DispalyElement {

    lateinit var weatherData:WeatherData
    var temp:Float=0.0f;
    var humidty:Float=0.0f;
    constructor(weatherData: WeatherData){//传入被观察者-完成订阅
        this.weatherData=weatherData
        weatherData.registerObserver(this)
    }
    override fun display() {
        LogUtils.d("$temp--$humidty")
    }

    override fun update() {

        this.temp=this.weatherData.getTemp()
        this.humidty=this.weatherData.getHumidity()
        display()
    }
}